// Strip off any frame that may surround the page.

// if (self != top) window.open(self.location.href,"_top","",true);
// I would use the above code but Opera 8.51 goes into an infinite loop
// (fixed in Opera 9.0 Beta).  The following works even in Opera 8.51...
if (self != top) {window.open("http://www.garrett.nildram.co.uk/calendar/scw.htm","_top","",true);}

// Set up address obfuscation variables
var	a='ma',		b='il',		c='to:',
	d='&#115;&#99;&#119;' + '&#102;&#101;&#101;&#100;&#98;&#97;&#99;&#107;',
	e='&#64;'+'&#116;&#97;&#114;&#114;&#103;&#101;&#116;'+
	  '&#46;'+'&#105;&#110;&#102;&#111;',
	f='?sub',	g='ject=';

function toggleStrict()
    {// Turn the Strict date processing option on or off

     scwBlnStrict = !scwBlnStrict;
     document.getElementById('btnToggleStrict').value =
        'Turn o' + ((scwBlnStrict)?'ff':'n') + ' strict dates';
    };

function toggleMonth()
    {// Turn the Out-of-month date visibility and selectability on or off

     scwOutOfMonthDisable = !scwOutOfMonthDisable;
     scwOutOfMonthHide    = !scwOutOfMonthHide;

     document.getElementById('btnToggleMonth').value =
        'Turn o' + ((scwOutOfMonthDisable)?'ff':'n') + ' out-of-month date display';
    };

function toggleDrag()
    {// Turn the calendar dragging option on or off

     scwAllowDrag = !scwAllowDrag;
     document.getElementById('btnToggleDrag').value =
        'Turn o' + ((scwAllowDrag)?'ff':'n') + ' dragging';
    };

function toggleWeekNumbers()
    {// Turn the week number display on or off

     scwWeekNumberDisplay= !scwWeekNumberDisplay;
     document.getElementById('btnToggleWeeks').value =
        'Turn o' + ((scwWeekNumberDisplay)?'ff':'n') + ' week numbering';
    };

function trivialAlert(alertText)
    {// Run this when the calendar closes
     alert(alertText);
    };

function setWeekDay(myEle)
    {// Set the displayed start day of the week

     scwWeekStart = parseInt(myEle.value,10);
     for (i=0;i<scwArrWeekInits.length;i++)
        {document.getElementById('scwWeekInit'+i).innerHTML =
            scwArrWeekInits[(i+parseInt(myEle.value,10))%scwArrWeekInits.length];
        }

     // Adjust the disabled days for the changed start day
     setSCWdays();
    };

function setBaseDay(myEle)
    {// Set the week numbering Base day
     scwWeekNumberBaseDay = parseInt(myEle.value,10);
    };

function setSCWdays()
    {// Set the day disabling array to the pattern selected in the
     // demonstration options.

     for (j=0;j<7;j++)
        {for (var i=0;i<scwEnabledDay.length;i++)
            {if ((i+scwWeekStart)%7==j)
				{scwEnabledDay[i] = !document.getElementById('cbDay'+j).checked;}
			}
         if (scwDateNow.getDay()==j)
            {scwActiveToday = !document.getElementById('cbDay'+j).checked;}
        }
    };

function easterDay(inYear)
    {// Determine Easter Day for a year

     var a = inYear%19              +  1,
         b = Math.floor(inYear/100) +  1,
         c = Math.floor(3*b/4)      - 12,
         d = (11*a+Math.floor((8*b+5)/25)+15-c)%30;

     d += (d<0)?30:0;
     d += (d==24||(d==25&&a>11))?1:0;

     var e = 44-d+((d>23)?30:0);

     return (new Date(inYear,2,(e+(7-((Math.floor(5*inYear/4)-10-c)+e)%7))));
    };

function writeEmailLink(h,i,j,k)
	{document.write('<a href="'+a+b+c+d+e+f+g+h+'" title="'+i+'" tabindex="'+k+'">'+j+'<\/a>');};

function formatString(a)	{return a.replace(/&lt;/g,'<').replace(/&gt;/g,'>').replace(/&amp;/g,'&');};

function showDate()
	{var lastModDate = new Date(document.lastModified);

	 document.write(((lastModDate==''||isNaN(lastModDate))
						?'an&nbsp;unknown&nbsp;date'
						:formatDate(lastModDate)
				   )
				  );

	 function formatDate(rawDate)
		{var arrMonthNames = ['January',  'February', 'March',
							  'April',    'May',      'June',
							  'July',     'August',   'September',
							  'October',  'November', 'December'],
			 arrSuffices    = ['st','nd','rd']
			 thisDate       = rawDate.getDate();

		 return thisDate
				+ '<sup>'
				+   (((thisDate> 3 && thisDate<21) ||
					  (thisDate>23 && thisDate<31)
					 )?'th':arrSuffices[thisDate%10-1]
					)
				+ '</sup>&nbsp;'
				+ arrMonthNames[rawDate.getMonth()] + '&nbsp;'
				+ rawDate.getFullYear();
		};
	};

function onLoad()
    {// Set demonstration option defaults

	   if (new Date()<new Date(2010,9,10))
			{alert('Greetings,\n\n' +
						'Please note that this site has just changed host away from Opal who caused the\n' +
			      'recent extended down time. Thank you for your patience.\n\n'+
						'The URL http://www.tarrget.info/calendar/scw.htm remains the correct address.\n\n' +
						'I am also in the process of creating a community support site at ' +
						'http://jscalendars.webs.com, I will be adding to it over time and ' +
						'I hope that people will both ask and answer questions in the fora there.\n\n' +
						'This message will self destruct on 10/10/2010.\n\n' +
						'Anthony');
			}
		
     document.getElementById('btnToggleStrict').value =
        'Turn o' + ((scwBlnStrict)?'ff':'n') + ' strict dates';

     document.getElementById('btnToggleMonth').value =
        'Turn o' + ((scwBlnStrict)?'ff':'n') + ' out-of-month date display';

     document.getElementById('btnToggleDrag').value =
        'Turn o' + ((scwAllowDrag)?'ff':'n') + ' dragging';

     document.getElementById('btnToggleWeeks').value =
        'Turn o' + ((scwWeekNumberDisplay)?'ff':'n') + ' week numbering';

     document.getElementsByName('startDay')[scwWeekStart].checked=true;
     document.getElementsByName('baseDay')[scwWeekNumberBaseDay].checked=true;

     // Disable a specific date

     scwDisabledDates[0] =  new Date(scwDateNow.getFullYear(),scwDateNow.getMonth(),14);

     // Disable a range of dates by specifying the start and end date

     scwDisabledDates[1] = [new Date(scwDateNow.getFullYear(),scwDateNow.getMonth(),28),
                            new Date(scwDateNow.getFullYear(),scwDateNow.getMonth()+1,4)];

     // Disable every Good Friday and Easter Monday in the calendar's range of years

     for (var i=scwBaseYear;i<(scwBaseYear+scwDropDownYears);i++)
        {var dtEasterDay = easterDay(i);    // return Easter Sunday
         scwDisabledDates[scwDisabledDates.length] = new Date(dtEasterDay.setDate(dtEasterDay.getDate()-2));
         scwDisabledDates[scwDisabledDates.length] = new Date(dtEasterDay.setDate(dtEasterDay.getDate()+3));
        }

     // Disable any week days as selected in the demonstration options

     setSCWdays();

     // Strict HTML method of setting TARGET = '_blank'

     if (!document.getElementsByTagName) {return;}

     var anchors = document.getElementsByTagName('a');
     for (var i=0;i<anchors.length;i++)
        {if (anchors[i].getAttribute('href') &&
             anchors[i].getAttribute('rel') == 'external')
            {anchors[i].target = '_blank';}
        }
    };
